package com.ifamily.dao.impl;

import java.util.Collection;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ifamily.dao.GenericDao;

public class GenericDaoImpl<T> extends HibernateDaoSupport implements GenericDao<T>{

	@Resource(name="hibernateTemplate")
	private HibernateTemplate hibernateTemplate;
	
	
	private final Class<T> clazz;
	
	public GenericDaoImpl(Class<T> clazz)
	{
		this.clazz = clazz;
	}
	
	@Override
	public void saveOrUpdate(T entity) {
		getHibernateTemplate().saveOrUpdate(entity);
	}

	@Override
	public void deleteEntity(T entity) {
		getHibernateTemplate().delete(entity);
		
	}

	@Override
	public void saveOrUpdateAll(Collection<T> entities) {
		getHibernateTemplate().saveOrUpdateAll(entities);
	}

	@Override
	public T findById(int id) {

		return getHibernateTemplate().load(clazz, id);
	}

}
